package com.dahua.util;

import com.dahua.aop.UserService;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author chen_MingLiang
 * @version 1.0
 * @date 2020/1/29 18:54
 */
public class CglibUtil {
	public static Object getCglibProxy(){
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(UserService.class);
		enhancer.setCallback((MethodInterceptor) (o, method, objects, methodProxy) -> {
			System.out.println("cglib AOP");
			Object returnVal = methodProxy.invokeSuper(o, objects);
			return returnVal;
		});
		Object o = enhancer.create();
		return o;
	}
}
